﻿function RenderSettingsPage()
{
    var setting;
    if (setting = Controller.QueryString['setting'])
    {
        RenderSettingsPage.Setting=setting ;
    } 
    
    RegisterSettingsTemplates ();
    var tabs = { 'General' : RenderSettingsPage.GENERAL,
                 'Categories' : RenderSettingsPage.CATEGORY,
                 'Calendars' : RenderSettingsPage.CALENDAR,
                 'Custom Properties' : RenderSettingsPage.PROPERTY ,
                 'Custom Reports' : RenderSettingsPage.REPORT 
                 };
    var object = Factory.empty ('SettingsPage');
    object.workspace = RenderSettingsPage.Render(RenderSettingsPage.Setting);
    object.tabs = ''; 
    for (var i in tabs)
    {
        object.tabs += Factory.write ({'template' : RenderSettingsPage.Setting==tabs[i] ? 'SettingsTabOff' : 'SettingsTabOn',
                                        'name' : i,
                                        'value' : tabs[i] 
                                      });  
    }  
    return object.draw ();
}


function RegisterSettingsTemplates()
{ 
    registerTemplate ("RenderGeneralNormalRow", RenderGeneralNormalRow);
    registerTemplate ("RenderGeneralInput", RenderGeneralInput);
    registerTemplate ("RenderGeneralTitleRow", RenderGeneralTitleRow);
    registerTemplate ("RenderGeneralSettingsForm", RenderGeneralSettingsForm);
    registerTemplate ("SettingsSpacerRow", SettingsSpacerRow);
    registerTemplate ("RenderCategoryNormalRow", RenderCategoryNormalRow);
    registerTemplate ("RenderCategorySelectedRow", RenderCategorySelectedRow);
    registerTemplate ("RenderCalendarNormalRow", RenderCalendarNormalRow); 
    registerTemplate ("RenderCalendarSelectedRow", RenderCalendarSelectedRow);
    registerTemplate ("RenderPropertyNormalRow", RenderPropertyNormalRow);
    registerTemplate ("RenderPropertySelectedRow", RenderPropertySelectedRow);
    registerTemplate ("GeneralCreateForm", GeneralCreateForm);
    registerTemplate ("RenderReportNormalRow", RenderReportNormalRow);
    registerTemplate ("RenderReportSelectedRow", RenderReportSelectedRow);   
    registerTemplate ("SettingsPage", SettingsPage);  
    registerTemplate ("SettingsTabOn", SettingsTabOn);  
    registerTemplate ("SettingsTabOff", SettingsTabOff);   
}


function ReloadSettingsPage(setting)
{ 
    RenderSettingsPage.Setting = setting; 
    Controller.Reload ();
}
function FCKeditor_OnComplete( editorInstance )
{ 
    editorInstance.Events.AttachEvent( 'OnSelectionChange', function () { 
																var oEditor = FCKeditorAPI.GetInstance('ict') ;
																var content = oEditor.GetHTML();
																var spacer='<p>&nbsp;</p>',content = oEditor.GetHTML();
																while (content.indexOf(spacer) >= 0) content=content.replace (spacer,''); 
																Controller.currentreportcontent = content; 
															} ) ;
	var spacer='<p>&nbsp;</p>',content = editorInstance.GetHTML();
	while (content.indexOf(spacer) >= 0) content=content.replace (spacer,''); 
	Controller.currentreportcontent = content; 
	window.resizer.invoke ();
}

function OnSettingsPageRender()
{
    var setting,dc=document.getElementById ('dcal');  
    if (dc) dc.style.display='none'; 
    AttachResizer ('tbsettingstable', 0, 100);
    AttachResizer ('dcesettingstable', 0 );  
	if (Controller.QueryString['id'] && Controller.QueryString['id']>0 && RenderSettingsPage.Setting==RenderSettingsPage.CALENDAR)
	{
		Controller.SelectedCalendar = Controller.QueryString['id']
	//	Controller.QueryString['id'] = null;
	    var array = GetCalendarById(Controller.SelectedCalendar);
	    var map = new EventCalendar (array);
	    map.container = 'dcalendarpreview';
	    map.invoke ();
	}
	
	if (Controller.QueryString['id'] && Controller.QueryString['id']>0 && RenderSettingsPage.Setting==RenderSettingsPage.REPORT)
	{
		Controller.SelectedReport = Controller.QueryString['id']  
		
		
		var dw = document.getElementById ('ict');
		if (!dw)
		{
			//alert ('No textarea to replace');
			return false;
		}
	
		var WorkspaceOffset = 10;
			
		dw.invoke = function ()
		{ 
			this.style.width  = ( window_w() - docx(this) - WorkspaceOffset - 10) + 'px';
			//this.style.height = ( window_h() - docy(this) - 20 ) + 'px';   
			
			var ifr = document.getElementsByTagName ('IFRAME');
			for (var x=0;x<ifr.length;x++)
			{
				ifr[x].style.width  = ( window_w() - docx(ifr[x]) - WorkspaceOffset - 10) + 'px';
				ifr[x].style.height = 200 + 'px';//( window_h() - docy(ifr[x]) - 30 ) + 'px';   
			}
			
		}
		window.resizer.subscribe (dw); 
		window.resizer.invoke ();
		 
			
			
		var oFCKeditor 	= new FCKeditor( 'ict' ) ;
		var sBasePath 	= "/fckeditor/";
		var sToolbar	= "ESP";
		oFCKeditor.BasePath		= sBasePath ;
		//oFCKeditor.ToolbarSet 	= sToolbar ;
		oFCKeditor.ReplaceTextarea() ;
			
		return true;
		
		if (!Controller.editor)
		{   
			
			var sBasePath 	= "/fckeditor/";
			var sSkin 		= "office2003";
			var sToolbar	= "ESP";
			Controller.editor = new FCKeditor( 'ict' ) ;
			Controller.editor.BasePath = sBasePath; 
						
//			if ( sSkin != null )
//			{
//				var sSkinPath = sBasePath + 'editor/skins/' + sSkin + '/' ;
//				Controller.editor.Config['SkinPath'] = sSkinPath ;
//			
//				// The following switch is optional. It is done to enhance the loading
//				// time of the toolbar, by preloading the images used on it.
//				switch ( sSkin )
//				{
//					case 'office2003' :
//						Controller.editor.Config['PreloadImages'] =
//							sSkinPath + 'images/toolbar.start.gif' + ';' +
//							sSkinPath + 'images/toolbar.end.gif' + ';' +
//							sSkinPath + 'images/toolbar.bg.gif' + ';' +
//							sSkinPath + 'images/toolbar.buttonarrow.gif' ;
//						break ;
//			
//					case 'silver' :
//						Controller.editor.Config['PreloadImages'] =
//							sSkinPath + 'images/toolbar.start.gif' + ';' +
//							sSkinPath + 'images/toolbar.end.gif' + ';' +
//							sSkinPath + 'images/toolbar.buttonbg.gif' + ';' +
//							sSkinPath + 'images/toolbar.buttonarrow.gif' ;
//						break ;
//				}
//			} 
//			
//			 
//			Controller.editor.ToolbarSet = sToolbar ;
			Controller.editor.ReplaceTextarea() ;
		}
	}
	
	
	
	
	
}
var constant = ['GENERAL','CATEGORY','CALENDAR','PROPERTY','REPORT'];
for (var x in constant) RenderSettingsPage[ constant[x] ]=x;
 
//RenderSettingsPage.GENERAL  = 0; 
//RenderSettingsPage.CATEGORY = 1; 
//RenderSettingsPage.CALENDAR = 2; 
//RenderSettingsPage.PROPERTY = 3; 

RenderSettingsPage.Setting = RenderSettingsPage.GENERAL; 

RenderSettingsPage.RenderGeneral = function ()
{
    var htm = '';
	var dropdown, object = Factory.empty ('RenderGeneralNormalRow'), caption = Factory.empty ('RenderGeneralTitleRow');  
    for (var x in window.config)
	{  
		switch (x)
		{
			case 'defaultcalendar':
			    dropdown = { 
			                'id' : 'config'+x+'', 
						    'selected' : window.config[x], 
						    'collection' : window.calendars,   
						    'name' : 'calendar_name',  
						    'key' : 'id'
						    }  
			    object.name = 'Default Calendar';
			    object.content = Toolbar.selector (dropdown);  
			    
			    caption.title = 'For new events:';
			    
			    htm += caption.draw (); 
			    htm += object.draw (); 
				break;
			case 'defaultfields':
				window.hash = parseInt(window.config[x]); 				
			    object.name = 'Default Fields'; 
				object.content = '<table><tr>'; 
				object.content += Toolbar.fieldlist (window.hash, 'window.hash=bite(window.hash, parseInt(this.value));');   
				object.content += '</tr></table>'; 
			    
			    caption.title = 'For searches:';
								
			    htm += caption.draw (); 
			    htm += object.draw (); 
				break;
			case 'defaultroom':			
			    dropdown = { 
			                'id' : 'config'+x+'', 
						    'selected' : window.config[x], 
						    'collection' : window.rooms,   
						    'name' : 'RoomName',  
						    'key' : 'ID'
						    }  
			    object.name = 'Default Room';
			    object.content = Toolbar.selector (dropdown);  
			    htm += object.draw (); 
				break;
			default:
			    object.name = ucfirst(x);
			    object.content = Factory.write ( { 'index' : x, 'value' : window.config[x], 'template' : 'RenderGeneralInput' });  
			    htm += object.draw (); 
				break;
		} 
		
        htm += Factory.write ( { 'template' : 'SettingsSpacerRow', 'colspan' : 2 } );  
	} 
    return Factory.write ( { 'template' : 'RenderGeneralSettingsForm', 'content' : htm } );  
}

RenderSettingsPage.RenderCategory = function ()
{
	var d=new dgrid();
	d.key="esettingstable";
	d.showall = true; 
	d.editable = true; 
	d.selected = Controller.SelectedCategory;
	d.bordercolor = "#FFFF99";
	d.headerstyle="border-bottom:solid 1px #cccccc;color:gray;height:24px;background-color:#eeeeee;color:#666";
    d.headertransform = function ()
    {
        return Factory.write ({ 'template' : 'GeneralCreateForm' , 
                                    'name' : 'category', 
                                    'command' : 'CreateCategory'  
                                });   
    }
    d.transform = function (row)
    { 
        var ok=parseInt(Controller.QueryString['id'])==parseInt(row['id']); 
        var object = { 'template' : ok ? 'RenderCategorySelectedRow' : 'RenderCategoryNormalRow',  
                        'gridid' : this.id }  
        for (var x in row) object[x]=row[x];
        return Factory.write (object);  
    }
	d.select = function (i)
	{
	    Controller.SelectedCategory = i;
	    Controller.Reload ();
	}
 
	d.cellpadding= 2;
	d.rows = window.folders; 
    return d.draw(); 
}


RenderSettingsPage.RenderReport = function ()
{ 
	var d=new dgrid();
	d.key="ereporttable";
	d.showall = true; 
	d.editable = true; 
	d.selected = Controller.SelectedReport;
	d.bordercolor = "#FFFF99";
	d.headerstyle="border-bottom:solid 1px #cccccc;color:gray;height:24px;background-color:#eeeeee;color:#666";
    d.headertransform = function ()
    {
        return Factory.write ({ 'template' : 'GeneralCreateForm' , 
                                    'name' : 'report', 
                                    'command' : 'CreateReport'  
                                });   
    }
    d.transform = function (row)
    { 
        var ok=parseInt(Controller.QueryString['id'])==parseInt(row['id']); 
        var object = { 'template' : ok ? 'RenderReportSelectedRow' : 'RenderReportNormalRow',  
                        'gridid' : this.id }  
        for (var x in row) object[x]=row[x];
        return Factory.write (object);  
    }
	d.select = function (i)
	{
	    Controller.SelectedReport = i;
	    Controller.Reload ();
	}
 
	d.cellpadding= 2;
	d.rows = window.reports; 
    return '<form action="#" method="post">' + d.draw() + '</form>'; 
}


RenderSettingsPage.RenderCalendar = function ()
{
	var d=new dgrid();
	d.key="ecalendartable";
	d.showall = true;  
	d.headercolor = '#FFFFCC';  
	d.showcolumns = true;  
	d.selected = Controller.SelectedCalendar;
	d.rows = window.calendars;
	d.columns = new Array ('Name','Max Events','Text length','Font size','Type');
	d.headerstyle="border-bottom:solid 1px #cccccc;color:gray;height:24px;background-color:#eeeeee;color:#666";
    d.headertransform = function ()
    {
        return Factory.write ( { 'template' : 'GeneralCreateForm' , 
                                    'name' : 'calendar', 
                                    'command' : 'CreateCalendar'  
                                    });  
    }
    d.transform = function (row)
    { 
        var ok=parseInt(Controller.QueryString['id'])==parseInt(row['id']);
        
        var object = { 'template' : ok ? 'RenderCalendarSelectedRow' : 'RenderCalendarNormalRow',  
                        'calendar_view_name' : EventCalendar.Views[row['calendar_view']],  
                        'calendar_view_list' : Toolbar.selector ({ 
                                                    'onchange' : 'window.eventcalendar.retype(this.value)',
                                                    'ordinal' : true,
                                                    'selected' : row['calendar_view'],
                                                    'collection' : EventCalendar.Views 
                                               }),
                        'gridid' : this.id }  
        for (var x in row) object[x]=row[x];
		//object['maxevents'] = Controller.QueryString['id'] + '/' + row['id'];
        return Factory.write (object);   
    }
	d.select = function (i)
	{
	    Controller.SelectedCalendar = i;
	    Controller.Reload ();
	} 
	d.bordercolor = "#FFFF99";
	var htm=d.draw () ;
	htm += '<div id="dcalendarpreview">No calendar selected</div>';
    return htm;
}

RenderSettingsPage.RenderProperty = function ()
{ 
	var d=new dgrid();
	d.key="esettingstable";
	d.showall = true;  
	d.headercolor = '#FFFFFF';  
	d.showcolumns = true; 
	d.selected = Controller.SelectedProperty;
	d.rows = window.properties;
	d.columns = new Array ('Name','Type','Each','Text');
	d.headerstyle="border-bottom:solid 1px #cccccc;color:gray;height:24px;background-color:#eeeeee;color:#666";
    d.headertransform = function ()
    {
        return Factory.write ({ 'template' : 'GeneralCreateForm' , 
                                    'name' : 'custom property', 
                                    'command' : 'CreateProperty'  
                                    }); 
    }
    d.transform = function (row)
    { 		
        var ok = parseInt(Controller.QueryString['id'])==parseInt(row.id);
	    var dropdown = { 
	                    'id' : 'iproperty_type', 
				        'collection' : window.property_types,  
				        'selected' : row.property_type,  
				        'name' : 'type_name',  
				        'key' : 'id'
				        };  
        var object = { 'template' : ok ? 'RenderPropertySelectedRow' : 'RenderPropertyNormalRow',  
                        'shortname' : row.display_text.substr(0,50) + (row.display_text.length>50?'...':''),
                        'gridid' : this.id,
                        'type_name_list' : Toolbar.selector (dropdown) 
                        };  
        for (var x in row) object[x]=row[x];
        return Factory.write (object);   
    }
	d.select = function (i)
	{
	    Controller.SelectedProperty = i;
	    Controller.Reload ();
	} 
	d.bordercolor = "#FFFF99";
    return d.draw(); 
}


function GetCalendarById(id)
{
    return GetObjectByAttribute (window.calendars, 'id', id); 
}

function GetCustomPropertyByName(name)
{
    return GetObjectByAttribute (window.properties, 'property_name', name);  
}

function GetCustomPropertyById(id)
{
    return GetObjectByAttribute (window.properties, 'id', id);  
}

function AddCustomPropertyValue(value)
{
	var dt=document.getElementById ('addcp');
	if (!dt) return false;
	var value=dt.value;
	var pt=GetCustomPropertyById(Controller.SelectedProperty);
	pt.add (value);
	AttachCustomPropertyForm();
	Controller.Reload();
}

function RemoveCustomPropertyValue(value)
{
	var pt=GetCustomPropertyById(Controller.SelectedProperty);
    if (!pt) return null; 
	pt.remove (value);
	AttachCustomPropertyForm();
	Controller.Reload();
}

function ResetCustomPropertyForm()
{
	var dt=document.getElementById ('idisplay_text');
	var pt=GetCustomPropertyById(Controller.SelectedProperty);
    if (!dt) return null; 
    if (!pt) return null; 
    pt.display_text = dt.value;
    pt.valuelist = pt.display_text.split (',');
	AttachCustomPropertyForm();
	Controller.Reload();
}

function AttachCustomPropertyForm()
{
	HideTimeSelector(); 
	var dt=document.getElementById ('idisplay_text');
	var ds=document.getElementById ('dtimeselect');
	var pt=GetCustomPropertyById(Controller.SelectedProperty);
    if (!pt) return null; 
	ds.innerHTML        = pt.ValueTable (); 
	ds.style.display    ='inline';
	ds.style.width      = dt.offsetWidth;
	ds.style.left       = docx (dt);
	ds.style.top        = docy(dt) + dt.offsetHeight;
}

function getElementValue (elementname)
{
    var element = document.getElementById (elementname);
    if (!element) return '';
    return element.value;
}

function SaveProperty ()
{
	var pt=GetCustomPropertyById(Controller.SelectedProperty);
    var element = document.getElementById ('iproperty_type');
    pt.property_name=getElementValue('iproperty_name');
    pt.property_type=getElementValue('iproperty_type');
    pt.property_each=getElementValue('iproperty_each');
    pt.display_text=getElementValue('idisplay_text');
    pt.type_name=element.options[element.selectedIndex].text;
    pt.valuelist=pt.display_text.split(',');	 
    pt.save (); 
}

RenderSettingsPage.Renderer = new Array (
										 RenderSettingsPage.RenderGeneral, 
										 RenderSettingsPage.RenderCategory, 
										 RenderSettingsPage.RenderCalendar, 
										 RenderSettingsPage.RenderProperty, 
										 RenderSettingsPage.RenderReport);
RenderSettingsPage.Render = function (i) 
{
    var command = RenderSettingsPage.Renderer[i];
    if (typeof (command)=='function') return command();
}



function SaveConfig()
{
	for (var x in window.config)
	{
		dc=document.getElementById ('config' + x); 
		if (dc) window.config[x] = dc.value;
	}
	window.config['defaultfields'] = window.hash;
	
	var xml='';
	xml=''; 
	xml+='<config>\n'; 
	xml+=' <recordset>\n'; 
	xml+='  <record>\n';  
	for (var x in window.config)
	{                                                    
        xml+='<field name="' + x + '"><![CDATA[' + window.config[x] + ']]></field>\n';  
	}                                               
	xml+='  </record>\n';                         
	xml+=' </recordset>\n';  
	xml+='</config>\n';  
	wsdl(DATA_URL, OnSaveConfig, "Receiving save response...", xml) ;//wsdl (DATA_URL, OnSaveConfig, xml);
}


var RenderGeneralNormalRow = '';
RenderGeneralNormalRow += '<tr>';
RenderGeneralNormalRow += '<td align="right" nowrap>(name)</td>';
RenderGeneralNormalRow += '<td width="100%">(content)</td>';
RenderGeneralNormalRow += '</tr>'; 

var RenderGeneralInput = '<input id="config(index)" value="(value)" class="flat"/>'; 

var RenderGeneralTitleRow = ''; 
RenderGeneralTitleRow += '<tr>';
RenderGeneralTitleRow += '<td bgcolor="#FFFF99" colspan="2"><b>(title)</b><hr noshade color="#FFCC33"></td>';
RenderGeneralTitleRow += '</tr>';

var RenderGeneralSettingsForm = ''; 
RenderGeneralSettingsForm += '<div id="dcesettingstable" style="overflow:auto;">';
RenderGeneralSettingsForm += '<table width="100%">';
RenderGeneralSettingsForm += '<tr><td bgcolor="#FFFF99" colspan="2">Use this page to change program settings.';
RenderGeneralSettingsForm += '<hr noshade color="#FFCC33">';
RenderGeneralSettingsForm += '<b>Database Settings</b><hr noshade color="#FFCC33"></td></tr>'; 
RenderGeneralSettingsForm += '(content)<tr>';
RenderGeneralSettingsForm += '<td bgcolor="#FFFF99" colspan="2">';
RenderGeneralSettingsForm += '<input type=button value="Save Changes" onclick="SaveConfig()"/>';
RenderGeneralSettingsForm += '&nbsp;<a href="javascript:void(0)" onclick="ErrorReportEvent.invoke()" class=small>Report a problem</a> | ';
RenderGeneralSettingsForm += '&nbsp;<a href="javascript:void(0)" onclick="LoadIssueLogList()" class=small>View known issues</a> | ';
RenderGeneralSettingsForm += '&nbsp;<a href="eb-backup.php" class=small target=_blank>Backup/restore</a>'; 
RenderGeneralSettingsForm += '</td>';
RenderGeneralSettingsForm += '</tr>';
RenderGeneralSettingsForm += '</table>';
RenderGeneralSettingsForm += '</div>';

var SettingsSpacerRow = '';  
SettingsSpacerRow += '<tr>';
SettingsSpacerRow += '<td bgcolor="#FFFF99" colspan="(colspan)"><hr noshade color="#FFCC33"></td>';
SettingsSpacerRow += '</tr>'; 


var RenderCategoryNormalRow = '';
RenderCategoryNormalRow += '<tr>';
RenderCategoryNormalRow += '<td bgcolor="#FFFF99">&nbsp;'; 
RenderCategoryNormalRow += '<a style="color:#336699" href="./#view/settingspage/setting/' + RenderSettingsPage.CATEGORY + '/id/(id)">Edit</a>'; 
//RenderCategoryNormalRow += '<a href="javascript:void(0)" onclick="window.datagrids[(gridid)].select ((id))">Edit</a>'; 
RenderCategoryNormalRow += ' | '; 
RenderCategoryNormalRow += '<a href="javascript:void(0)" onclick="DeleteCategory ((id))">Delete</a>'; 
RenderCategoryNormalRow += '&nbsp;&nbsp;(title)'; 
RenderCategoryNormalRow += '</td>';
RenderCategoryNormalRow += '</tr>'; 
RenderCategoryNormalRow += '<tr>';
RenderCategoryNormalRow += '<td bgcolor="#FFFF99"><hr noshade color="#FFCC33"></td>';
RenderCategoryNormalRow += '</tr>';


var RenderCategorySelectedRow = '';
RenderCategorySelectedRow += '<tr>';
RenderCategorySelectedRow += '<td bgcolor="#FFFF99">&nbsp;'; 
RenderCategorySelectedRow += '<a style="color:#336699" href="./#view/settingspage/setting/' + RenderSettingsPage.CATEGORY + '/id/0">Cancel</a>';  
//RenderCategorySelectedRow += '<a href="javascript:void(0)" onclick="window.datagrids[(gridid)].select (0)">Cancel</a>';   
RenderCategorySelectedRow += ' | '; 
RenderCategorySelectedRow += '<a href="javascript:void(0)" onclick="DeleteCategory ((id))">Delete</a>'; 
RenderCategorySelectedRow += '&nbsp;&nbsp;';   
RenderCategorySelectedRow += '<input id="icn" class=flat value="(title)">';
RenderCategorySelectedRow += '<input onclick="SaveCategory ((id), document.getElementById(\'icn\').value)" ';
RenderCategorySelectedRow += ' type=button value="Save">';   
RenderCategorySelectedRow += '</td>';
RenderCategorySelectedRow += '</tr>';
RenderCategorySelectedRow += '<tr>';
RenderCategorySelectedRow += '<td bgcolor="#FFFF99"><hr noshade color="#FFCC33"></td>';
RenderCategorySelectedRow += '</tr>';


var RenderCalendarNormalRow = '';
RenderCalendarNormalRow += '<tr>';
RenderCalendarNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;';
RenderCalendarNormalRow += '<a style="color:#336699" href="./#view/settingspage/setting/' + RenderSettingsPage.CALENDAR + '/id/(id)">Edit</a>'; 
//RenderCalendarNormalRow += '<a href="javascript:void(0)" onclick="window.datagrids[(gridid)].select ((id))">Edit</a>';
RenderCalendarNormalRow += ' | ';
RenderCalendarNormalRow += '<a href="javascript:void(0)" onclick="DeleteCalendar ((id))">Delete</a>';
RenderCalendarNormalRow += '&nbsp;&nbsp;';  
RenderCalendarNormalRow += '(calendar_name)'; 
RenderCalendarNormalRow += '</td>';
RenderCalendarNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
RenderCalendarNormalRow += '(maxevents)';  
RenderCalendarNormalRow += '</td>';
RenderCalendarNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
RenderCalendarNormalRow += '(truncate)';  
RenderCalendarNormalRow += '</td>';
RenderCalendarNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
RenderCalendarNormalRow += '(fontsize)';  
RenderCalendarNormalRow += '</td>';
RenderCalendarNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
RenderCalendarNormalRow += '(calendar_view_name)';  
RenderCalendarNormalRow += '</td>';
RenderCalendarNormalRow += '';
RenderCalendarNormalRow += '<td bgcolor="#FFFF99" width="100%" nowrap>';
RenderCalendarNormalRow += '&nbsp;</td>';
RenderCalendarNormalRow += '</tr>';
RenderCalendarNormalRow += '<tr>';
RenderCalendarNormalRow += '<td colspan="6" bgcolor="#FFFF99"><hr noshade color="#FFCC33"></td>';
RenderCalendarNormalRow += '</tr>';
        
        
var RenderCalendarSelectedRow = '';
RenderCalendarSelectedRow += '<tr>';
RenderCalendarSelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;';
RenderCalendarSelectedRow += '<a style="color:#336699" href="./#view/settingspage/setting/' + RenderSettingsPage.CALENDAR + '/id/0">Cancel</a>';  
//RenderCalendarSelectedRow += '<a href="javascript:void(0)" onclick="window.datagrids[(gridid)].select (0)">Cancel</a>'; 
RenderCalendarSelectedRow += ' | ';
RenderCalendarSelectedRow += '<a href="javascript:void(0)" onclick="DeleteCalendar ((id))">Delete</a>';
RenderCalendarSelectedRow += '&nbsp;&nbsp;';  
RenderCalendarSelectedRow += '';
RenderCalendarSelectedRow += '<input id="calendar_name" onchange="window.eventcalendar.set(this.id, this.value)" class=flat value="(calendar_name)">';
RenderCalendarSelectedRow += '';
RenderCalendarSelectedRow += '</td>';
RenderCalendarSelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
RenderCalendarSelectedRow += '<input size=3 value="(maxevents)" id="maxevents" onchange="window.eventcalendar.set(this.id, this.value)" class=flat>'; 
RenderCalendarSelectedRow += '</td>';
RenderCalendarSelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
RenderCalendarSelectedRow += '<input size=3 value="(truncate)" id="truncate" onchange="window.eventcalendar.set(this.id, this.value)" class=flat>'; 
RenderCalendarSelectedRow += '</td>';
RenderCalendarSelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
RenderCalendarSelectedRow += '<input size=3 value="(fontsize)" id="fontsize" onchange="window.eventcalendar.set(this.id, this.value)" class=flat>'; 
RenderCalendarSelectedRow += '</td>';
RenderCalendarSelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;(calendar_view_list)</td>';
RenderCalendarSelectedRow += '<td bgcolor="#FFFF99" width="100%" nowrap>';
RenderCalendarSelectedRow += '<input type=button value="Save" onclick="window.eventcalendar.save();">';  
RenderCalendarSelectedRow += '<input type=button value="Preview" onclick="window.open(\'eb-calendar.html#(id)\');">';  
RenderCalendarSelectedRow += '&nbsp;</td>';
RenderCalendarSelectedRow += '</tr>';
RenderCalendarSelectedRow += '<tr>';
RenderCalendarSelectedRow += '<td colspan="6" bgcolor="#FFFF99"><hr noshade color="#FFCC33"></td>';
RenderCalendarSelectedRow += '</tr>';


var RenderPropertyNormalRow = '';
RenderPropertyNormalRow += '<tr>';
RenderPropertyNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
RenderPropertyNormalRow += '<a style="color:#336699" href="./#view/settingspage/setting/' + RenderSettingsPage.PROPERTY + '/id/(id)">Edit</a>'; 
//RenderPropertyNormalRow += '<a href="javascript:void(0)" onclick="window.datagrids[(gridid)].select ((id))">Edit</a>'; 
RenderPropertyNormalRow += ' | '; 
RenderPropertyNormalRow += '<a href="javascript:void(0)" onclick="DeleteProperty ((id))">Delete</a>'; 
RenderPropertyNormalRow += '&nbsp;&nbsp;';   
RenderPropertyNormalRow += '(property_name)'; 
RenderPropertyNormalRow += '</td>'; 
RenderPropertyNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;';  
RenderPropertyNormalRow += '(type_name)';   
RenderPropertyNormalRow += '</td>';  
RenderPropertyNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;';  
RenderPropertyNormalRow += '(property_each)';   
RenderPropertyNormalRow += '</td>';  
RenderPropertyNormalRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;(shortname)</td>';  
RenderPropertyNormalRow += '<td bgcolor="#FFFF99" width="100%" nowrap>';  
RenderPropertyNormalRow += '&nbsp;</td>';
RenderPropertyNormalRow += '</tr>'; 
RenderPropertyNormalRow += '<tr>';
RenderPropertyNormalRow += '<td colspan="5" bgcolor="#FFFF99"><hr noshade color="#FFCC33"></td>';
RenderPropertyNormalRow += '</tr>'; 


var RenderPropertySelectedRow = '';
RenderPropertySelectedRow += '<tr>';
RenderPropertySelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;'; 
//RenderPropertySelectedRow += '<a href="javascript:void(0)" onclick="window.datagrids[(gridid)].select (0)">Cancel</a>'; 
RenderPropertySelectedRow += '<a style="color:#336699" href="./#view/settingspage/setting/' + RenderSettingsPage.PROPERTY + '/id/0">Cancel</a>'; 
RenderPropertySelectedRow += ' | '; 
RenderPropertySelectedRow += '<a href="javascript:void(0)" onclick="DeleteProperty ((id))">Delete</a>'; 
RenderPropertySelectedRow += '&nbsp;&nbsp;';   
RenderPropertySelectedRow += '';
RenderPropertySelectedRow += '<input id="iproperty_name" size=12 class=flat value="(property_name)">';
RenderPropertySelectedRow += '';
RenderPropertySelectedRow += '</td>'; 
RenderPropertySelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;(type_name_list)</td>';  
RenderPropertySelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;';  
RenderPropertySelectedRow += '<input class=flat id="iproperty_each" size=3 value="(property_each)">';    
RenderPropertySelectedRow += '</td>';  
RenderPropertySelectedRow += '<td bgcolor="#FFFF99" nowrap>&nbsp;';  
RenderPropertySelectedRow += '<input class=flat id="idisplay_text" onchange="ResetCustomPropertyForm()" onfocus="AttachCustomPropertyForm()" size=40 value="(display_text)">';         
RenderPropertySelectedRow += '</td>';  
RenderPropertySelectedRow += '<td bgcolor="#FFFF99" width="100%" nowrap>';
RenderPropertySelectedRow += '<input onclick="SaveProperty ()" type=button value="Save">'; 
RenderPropertySelectedRow += '';
RenderPropertySelectedRow += '&nbsp;</td>';
RenderPropertySelectedRow += '</tr>'; 
RenderPropertySelectedRow += '<tr>';
RenderPropertySelectedRow += '<td colspan="5" bgcolor="#FFFF99"><hr noshade color="#FFCC33"></td>';
RenderPropertySelectedRow += '</tr>'; 


var GeneralCreateForm = '';
GeneralCreateForm += '<div style="margin-bottom:10px">&nbsp;';
GeneralCreateForm += 'Create a new (name) named: <input id="txtcreate" class=flat value="">';
GeneralCreateForm += '<input onclick="(command) (document.getElementById(\'txtcreate\').value)" ';
GeneralCreateForm += ' type=button value="Create">';
GeneralCreateForm += '</div>';

var SettingsPage = '';
SettingsPage += '<table id="tbsettingstable" cellspacing="0" align=center cellpadding="0" height="100%" width="100%" bgcolor="#FFCC33">';
SettingsPage += '<tr><td>&nbsp;<b>Settings</b></td></tr>';
SettingsPage += '<tr><td>';
SettingsPage += '<table bgcolor="#FFCC33" cellspacing="0" cellpadding="4">';
SettingsPage += '<tr>(tabs)<td width="100%">&nbsp;</td>';
SettingsPage += '</tr>';
SettingsPage += '</table>';
SettingsPage += '</td></tr>';
SettingsPage += '<tr><td bgcolor="#FFFF99" height="100%" valign="top">(workspace)</td></tr>';
SettingsPage += '</table>';




var RenderReportNormalRow = '';
RenderReportNormalRow += '<tr>';
RenderReportNormalRow += '<td bgcolor="#FFFF99">&nbsp;'; 
RenderReportNormalRow += '<a onclick="Controller.editor=null" style="color:#336699" href="./#view/settingspage/setting/' + RenderSettingsPage.REPORT + '/id/(id)">Edit</a>';  
RenderReportNormalRow += ' | '; 
RenderReportNormalRow += '<a href="javascript:void(0)" onclick="DeleteReport ((id))">Delete</a>'; 
RenderReportNormalRow += '&nbsp;&nbsp;(title)'; 
RenderReportNormalRow += '</td>';
RenderReportNormalRow += '</tr>'; 
RenderReportNormalRow += '<tr>';
RenderReportNormalRow += '<td bgcolor="#FFFF99"><hr noshade color="#FFCC33"></td>';
RenderReportNormalRow += '</tr>';


var RenderReportSelectedRow = '';
RenderReportSelectedRow += '<tr>';
RenderReportSelectedRow += '<td bgcolor="#FFFF99">&nbsp;'; 
RenderReportSelectedRow += '<a style="color:#336699" href="./#view/settingspage/setting/' + RenderSettingsPage.REPORT + '/id/0">Cancel</a>';   
RenderReportSelectedRow += ' | '; 
RenderReportSelectedRow += '<a href="javascript:void(0)" onclick="DeleteReport ((id))">Delete</a>'; 
RenderReportSelectedRow += '&nbsp;&nbsp;';   
RenderReportSelectedRow += '<input id="icn" class=flat value="(title)">';
RenderReportSelectedRow += '<input onclick="SaveReport ((id), document.getElementById(\'icn\').value, document.getElementById(\'ict\').value)" ';
RenderReportSelectedRow += ' type=button value="Save">';   
RenderReportSelectedRow += '</td>'; 
RenderReportSelectedRow += '</tr>';
RenderReportSelectedRow += '<tr>';
RenderReportSelectedRow += '<td bgcolor="#FFFF99"><textarea name="ict" id="ict" rows="10" cols=75>(templatebody)</textarea></td>';
RenderReportSelectedRow += '</tr>';
RenderReportSelectedRow += '<tr>';
RenderReportSelectedRow += '<td bgcolor="#FFFF99"><hr noshade color="#FFCC33"></td>';
RenderReportSelectedRow += '</tr>';




var SettingsTabOn = '<td nowrap>&nbsp;<a href="./#view/settingspage/setting/(value)">(name)</a>&nbsp;</td>';
//var SettingsTabOn = '<td nowrap>&nbsp;<a href="javascript:void(0)" onclick="ReloadSettingsPage((value))">(name)</a>&nbsp;</td>';
var SettingsTabOff = '<td nowrap bgcolor="#FFFF99">&nbsp;<b>(name)</b>&nbsp;</td>';
